package com.codeoss.framework.pagebean;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.codeoss.framework.context.YunContext;
import com.codeoss.framework.view.clientscript.ClientPageOpenClickScript;
import com.codeoss.framework.view.clientscript.JsWindow;
import com.codeoss.framework.view.pagebean.ListViewPageBean;
import com.codeoss.module.ir.model.IrReport;
import com.codeoss.module.ir.service.IIrReportService;

@Service
public class ReportListPagePageBean extends ListViewPageBean{
	@Autowired
	private IIrReportService irReportService;
	
	public void doDesign() {
		YunContext yunContext=YunContext.getCurrentContext();
		yunContext.setRenderCompleted(true);
		List<Long> idList=getSelectedKeyValueList();
		if(idList==null || idList.size()==0) {
			throw new RuntimeException("请选择项");
		}
		IrReport irReport=irReportService.getById(idList.get(0));
		String reportType=irReport.getReportType();	
		if("detailReport".equals(reportType)) {
			ClientPageOpenClickScript clientPageOpenClickScript=new ClientPageOpenClickScript();
			clientPageOpenClickScript.setName(irReport.getName());
			clientPageOpenClickScript.setEnv(ClientPageOpenClickScript.ENV_DEV);
			Map<String,Object> paraMap=new HashMap<String,Object>();
			clientPageOpenClickScript.setParaMap(paraMap);
			paraMap.put("code", irReport.getCode());
			clientPageOpenClickScript.setPageCode("detail-report-designer");
			yunContext.addClientScript(clientPageOpenClickScript);
		}else if("summaryReport".equals(reportType)) {
			ClientPageOpenClickScript clientPageOpenClickScript=new ClientPageOpenClickScript();
			clientPageOpenClickScript.setName(irReport.getName());
			clientPageOpenClickScript.setEnv(ClientPageOpenClickScript.ENV_DEV);
			Map<String,Object> paraMap=new HashMap<String,Object>();
			clientPageOpenClickScript.setParaMap(paraMap);
			paraMap.put("code", irReport.getCode());
			clientPageOpenClickScript.setPageCode("summary-report-designer");
			yunContext.addClientScript(clientPageOpenClickScript);
		}else {
			JsWindow jsWindow=JsWindow.open("ureport/designer?_u=db:"+irReport.getCode());
			yunContext.addClientScript(jsWindow);
		}
	}
}
